package com.api.tournament.queue;


import java.util.Objects;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * 赛事开始监听
 */
public class TournamentStartDelayedMessage implements Delayed {

    private String tournamentName;   // 赛事名称
    private Long tournamentId;   // 赛事id
    private Long startDate;   // 开始时间


    /**
     * 获得延迟时间 过期时间减去当前时间
     * @param unit
     * @return
     */
    @Override
    public long getDelay(TimeUnit unit) {
        long remaining = startDate - System.currentTimeMillis();
        return unit.convert(remaining, TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        return (int) (this.getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS));
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        TournamentStartDelayedMessage that = (TournamentStartDelayedMessage) o;
        return Objects.equals(getTournamentId(), that.getTournamentId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getTournamentId());
    }

    public String getTournamentName() {
        return tournamentName;
    }

    public void setTournamentName(String tournamentName) {
        this.tournamentName = tournamentName;
    }

    public Long getTournamentId() {
        return tournamentId;
    }

    public void setTournamentId(Long tournamentId) {
        this.tournamentId = tournamentId;
    }

    public Long getStartDate() {
        return startDate;
    }

    public void setStartDate(Long startDate) {
        this.startDate = startDate;
    }
}
